
// gcc -ggdb test.c -o cli

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdlib.h>

#include "../src/public.h"

#define MAXLINE 255
int		port = 9854;

struct log_msg_t logmsg;

int main(int argc, char *argv[])
{
    struct sockaddr_in pin;
	int n;
    int		sock_fd;

    bzero(&pin, sizeof(pin));
    pin.sin_family = AF_INET;
    inet_pton(AF_INET, "127.0.0.1", &pin.sin_addr);
    pin.sin_port = htons(port);

    sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
    if (-1 == sock_fd)
    {
        perror("socket() error : ");
        exit(1);
    }

    while (1)
    {
        bzero(&logmsg, sizeof(logmsg));
        logmsg.magic = LOG_MAGIC;
        logmsg.level = 3;
        sprintf(logmsg.label, "%s", argv[0]);
        sprintf(logmsg.place, "%s : %s : %d", __FILE__, __FUNCTION__, __LINE__);
        sprintf(logmsg.msg, "%llu", time(NULL));

        n = sendto(sock_fd, &logmsg, sizeof(logmsg), 0, (struct sockaddr *)&pin, sizeof(pin));
        if (-1 == n)
        {
            perror("sendto() error : ");
            exit(1);
        }

        sleep(3);
    }

    close(sock_fd);

    return 0;
}

